package com.csw.shuanfa.CodeImprove.designPattern;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * 建造者模式
 */
public class BuilderD {
    /**
     * @param args
     */
    public static void main(String[] args) {
        Builder builder = new ConcreteBuilder();
        Director director = new Director(builder);
        director.construct();
        ProductBuilder product = builder.getResult();
        System.out.println(product);
    }
}

/**
 * 定义产品类
 */
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
@Data
class ProductBuilder {
    private String partA;
    private String partB;
    private String partC;
}

/**
 * 定义抽象建造者类
 */
abstract class Builder {
    public abstract void BuilderPartA();

    public abstract void BuilderPartB();

    public abstract void BuilderPartC();

    public abstract ProductBuilder getResult();

}

/**
 * 定义具体建造类
 */

class ConcreteBuilder extends Builder {
    ProductBuilder productBuilder = new ProductBuilder();

    @Override
    public void BuilderPartA() {
        productBuilder.setPartA("PartA");
    }

    @Override
    public void BuilderPartB() {
        productBuilder.setPartB("PartB");
    }

    @Override
    public void BuilderPartC() {
        productBuilder.setPartC("PartC");
    }

    @Override
    public ProductBuilder getResult() {
        return productBuilder;
    }
}

/**
 * 定义指挥者类
 */
class Director {
    private final Builder builder;

    public Director(Builder builder) {
        this.builder = builder;
    }

    public void construct() {
        builder.BuilderPartA();
        builder.BuilderPartB();
        builder.BuilderPartC();

    }
}